<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>用药方案</title>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link href="css/mui.min.css" rel="stylesheet"/>
    <link href="css/mui.picker.css" rel="stylesheet"/>
    <link href="css/mui.poppicker.css" rel="stylesheet"/>
    <link rel="stylesheet" href="css/grandeHealth.css"/>
    <style>
			.mui-table-view:before,.mui-table-view:after {height: 0; }
			.mui-navigate-right:after, .mui-push-right:after {font-size: 26px;}
	    	.mui-table-view-cell p,.mui-media-body{line-height: 40px;float: left;}
	    	.mui-table-view-cell p{float: right;margin-right: 25px;width: 65%;text-align:right;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}
	    	.mui-poppicker-header,.mui-picker{background: #fff;}
	    	.removes{background: #D84C29;width: 80%;margin: 20px auto;border: 0;color: #fff;display: none;}
	    	.mui-poppicker-body {height: 130px;}
	    	.mui-popup-button.mui-popup-button-bold {font-weight: normal;}
	    	.mui-content{margin-top:-75px}

    </style>
</head>
<body>
<!--<header>class="mui-bar mui-bar-nav" style="display: block;height: 64px;padding-top:20px">
  <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
  <button class="saveSubmit modifySubmit" style="float: right;">添加</button>
</header>-->
<div class="mui-content">
    <ul class="mui-table-view">
        <li class="mui-table-view-cell">
            <a href="javascript:;" class="mui-navigate-right">
                <div class="mui-media-body">药品名称</div>
                <p id="drugName"></p>
            </a>
        </li>
        <li class="mui-table-view-cell" id='showUserPicker'>
            <a href="javascript:;" class="mui-navigate-right">
                <div class="mui-media-body">药品数量</div>
                <p id='userResult'></p>
            </a>
        </li>
        <li class="mui-table-view-cell" id="showUserPicker1">
            <a href="javascript:;" class="mui-navigate-right">
                <div class="mui-media-body">用药剂量</div>
                <p id='userResult1'></p>
            </a>
        </li>
        <li class="mui-table-view-cell" id="showUserPicker2">
            <a href="javascript:;" class="mui-navigate-right">
                <div class="mui-media-body">用药频次</div>
                <p id='userResult2'></p>
            </a>
        </li>
        <li class="mui-table-view-cell" id="showUserPicker3">
            <a href="javascript:;" class="mui-navigate-right">
                <div class="mui-media-body">用药途径</div>
                <p id='userResult3'></p>
            </a>
        </li>
    </ul>
    <button type="button" class="mui-btn removes mui-btn-block">删除</button>
</div>
<p id="Objs" style="display: none;"></p>
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/mui.min.js"></script>
<script src="js/mui.picker.js"></script>
<script src="js/mui.poppicker.js"></script>
<script src="js/grandeHealth.js"></script>
<script src="js/medicalRecord.js"></script>
<script>
			var ObjAll = '';
			/*
			 * 药品名称取值
			 */						
			mui("body").on("tap", ".mui-table-view li:nth-child(1)", function() {
				showpage('drugName.html');
			})
			
			/*
			 * 添加用药方案
			 */
			var medications = JSON.parse(window.localStorage.getItem('yongyaofanan'));
			ObjAll = medications;
			var drugName = document.getElementById('drugName');
			var userResult = document.getElementById('userResult');
			var userResult1 = document.getElementById('userResult1');
			var userResult2 = document.getElementById('userResult2');
			var userResult3 = document.getElementById('userResult3');

			if(medications != null){
				if(medications.drunam == undefined && medications.unit == undefined){
					drugName.innerHTML = '';
				}else if(medications.drunam == '' && medications.unit == ''){
					drugName.innerHTML = '';
				}else{
					drugName.innerHTML = medications.drunam+'('+medications.unit+')';
				}

				if(medications.ypnum == undefined){
					userResult.innerHTML = '';
				}else{
					userResult.innerHTML = medications.ypnum;
				}
				
				if(medications.pian == undefined){
					userResult1.innerHTML = '';
				}else{
					userResult1.innerHTML = medications.pian;
				}
				
				if(medications.pc == undefined){
					userResult2.innerHTML = '';
				}else{
					userResult2.innerHTML = medications.pc;
				}
				
				if(medications.kfwyname == undefined){
					userResult3.innerHTML = '';
				}else{
					userResult3.innerHTML = medications.kfwyname;
				}
				
			}

            var alls = [];
            function adddrugschema() {
				if(drugName.innerHTML == '' || userResult.innerHTML == '' || userResult1.innerHTML == '' || userResult2.innerHTML == '' || userResult3.innerHTML == ''){
					mui.toast('请完善方案');
				}else{

				console.log(alls)
					if(window.localStorage.getItem('alls',JSON.stringify(alls)) != null){
						alls = (JSON.parse(window.localStorage.getItem('alls',alls)))//赋值
						console.log(alls)
					}
					localStorage.removeItem('yongyaofanan');//清值
					alls.push(ObjAll);
					console.log(ObjAll)
					window.localStorage.setItem('alls',JSON.stringify(alls))//存值
					$('.saveSubmit').attr("disabled", true);//判断按钮只可点击一次
				}
			}			$('.saveSubmit').removeClass('modifySubmit');
			
			mui("body").on("tap", ".saveSubmit", adddrugschema());

			/*
			 * 删除用药方案
			 */
			var urls = window.location.href;
			if(urls.indexOf("index") >= 0 ) { //if url中有index显示删除按钮
			  $('.removes').css('display','block');
			  $('.saveSubmit').addClass('modifySubmit').removeClass('saveSubmit').html('提交');
			}
						
			/*
			 * 修改提交用药方案
			 */
			var index = GetLocationParam("index");//需要修改的下标
			var medications = JSON.parse(window.localStorage.getItem('alls'));//取到原来所有存储的值		
			if(index != ''){				
				$('#drugName').html(medications[index].drunam+'('+medications[index].unit+')');
				$('#userResult').html(medications[index].ypnum);
				$('#userResult1').html(medications[index].pian);
				$('#userResult2').html(medications[index].pc);
				$('#userResult3').html(medications[index].kfwyname);				
			}

			mui("body").on("tap", ".modifySubmit", function() {
				
				if(ObjAll == null){
					
					
					//执行返回
				
				}else{
					
					if(ObjAll.drunam == undefined){
						ObjAll.drunam = medications[index].drunam;
					}
					
					if(ObjAll.unit == undefined){
						ObjAll.unit = medications[index].unit;
					}
					
					if(ObjAll.ypnum == undefined){
						ObjAll.ypnum = medications[index].ypnum;
					}
					if(ObjAll.pian == undefined){
						ObjAll.pian = medications[index].pian;
					}
					if(ObjAll.pc == undefined){
						ObjAll.pc = medications[index].pc;
					}
					if(ObjAll.kfwyname == undefined){
						ObjAll.kfwyname = medications[index].kfwyname;
					}
	
					medications[index] = ObjAll;
					alert(JSON.stringify(medications));
					window.localStorage.setItem('alls',JSON.stringify(medications))//存值
					localStorage.removeItem('yongyaofanan');
				}


				/*
				 * 提交返回新增病历页
				 */
				try {
					
					if(XHDOC_BROWSETYPE == 'IOS') {
					
						//调用IOS的返回事件
						
					} else if(XHDOC_BROWSETYPE == 'ANDROID') {
	
						//调用ANDROID的返回事件
	
					}else{
						mui.back();
					}
		
				} catch(e) {
					console.log(e);
				}		
	
			})
			
			/*
			 * 删除用药方案
			 */
			mui("body").on("tap", ".removes", function() {

				var btnArray = ['是', '否'];
				mui.confirm('是否删除该用药方案？', '', btnArray, function(e) {
					if (e.index == 0) {
						medications.splice(index,1);
						window.localStorage.setItem('alls',JSON.stringify(medications))//存值
						/*
						 * 提交返回
						 */
						try {
							
							if(XHDOC_BROWSETYPE == 'IOS') {
							
								//调用IOS的返回事件
								
							} else if(XHDOC_BROWSETYPE == 'ANDROID') {
			
								//调用ANDROID的返回事件
			
							}else{
								mui.back();
							}
				
						} catch(e) {
							console.log(e);
						}
						
					}
				})
				
			});
		
			(function($, doc) {
				$.init();
				$.ready(function() {
										
					/*
					 * 药品数量
					 */
					var userPicker = new $.PopPicker();
					userPicker.setData([
						{value: '1',text: '1'}, {value: '2',text: '2'}, {value: '3',text: '3'},
						{value: '4',text: '4'},{value: '5',text: '5'},{value: '6',text: '6'}
					]);	
					var showUserPickerButton = doc.getElementById('showUserPicker');
					var userResult = doc.getElementById('userResult');
					showUserPickerButton.addEventListener('tap', function(event) {
						userPicker.pickers[0].setSelectedValue(2);
						userPicker.show(function(items) {
							userResult.innerText = items[0].text;
							yongyaofanan.update('ypnum',items[0].text);
						});
					}, false);//-----------------------------------------	
					
					/*
					 * 用药剂量
					 */
					var userPicker1 = new $.PopPicker();
					userPicker1.setData([
						{value: '1',text: '一次1片'}, {value: '2',text: '一次2片'}, {value: '3',text: '一次3片'}
					]);
					var showCityPickerButton1 = doc.getElementById('showUserPicker1');
					var cityResult1 = doc.getElementById('userResult1');
					showCityPickerButton1.addEventListener('tap', function(event) {
						userPicker1.pickers[0].setSelectedValue(2);
						userPicker1.show(function(items) {
							cityResult1.innerText = items[0].text;
							yongyaofanan.update('pian',items[0].text);
						});
					}, false);//-----------------------------------------
					
					/*
					 * 用药频次
					 */
					var userPicker2 = new $.PopPicker();
					userPicker2.setData([
						{value: '1',text: '每日一次'}, {value: '2',text: '每日两次'}, {value: '3',text: '每日三次'}, 
						{value: '4',text: '每日四次'}, {value: '5',text: '每日五次'},{value: '6',text: '每日六次'}
					]);
					var showCityPickerButton2 = doc.getElementById('showUserPicker2');
					var cityResult2 = doc.getElementById('userResult2');
					showCityPickerButton2.addEventListener('tap', function(event) {
						userPicker2.pickers[0].setSelectedValue(2);
						userPicker2.show(function(items) {
							cityResult2.innerText = items[0].text;
							yongyaofanan.update('pc',items[0].text);
						});
					}, false);//-----------------------------------------

					/*
					 * 用药途径
					 */
					var userPicker3 = new $.PopPicker();
					userPicker3.setData([
						{value: '1',text: '口服'},{value: '2',text: '皮下'},
						{value: '3',text: '外用'}, {value: '4',text: '吸入'}
					]);
					var showCityPickerButton3 = doc.getElementById('showUserPicker3');
					var cityResult3 = doc.getElementById('userResult3');
					showCityPickerButton3.addEventListener('tap', function(event) {
						userPicker3.pickers[0].setSelectedValue(2);
						userPicker3.show(function(items) {
							cityResult3.innerText = items[0].text;
							yongyaofanan.update('kfwyname',items[0].text);
						});
					}, false);//-----------------------------------------
				});

			})(mui, document);
						 

</script>
</body>
</html>